<template>
	<view >
		<!-- 收获地址的盒子 -->
		<view class="address-choose-box" v-if="JSON.stringify(address)==='{}'">
			<button class="btnChooseAddress" type="primary" size="mini" @click="chooseAddress">请选择收获地址</button>
		</view>
		<!-- 收货信息的盒子 -->
		<view class="address-info-box" v-else @click="chooseAddress">
			<!-- 第一行，显示收货人的名字和电话 -->
			<view class="row1">
				<view class="row1-left">
					<view class="username">收货人: <text>{{address.userName}}</text></view>
				</view>
				<view class="row1-right">
					<view class="phone">电话：<text>{{address.telNumber}}</text> </view>
					<uni-icons type="arrowright" size="16"></uni-icons>
				</view>
			</view>
			<!-- 第二行，显示收货人的地址 -->
			<view class="row2">
				<view class="row2-left">收货地址：</view>
				<view class="row2-right">{{addrStr}}</view>
			</view>
		</view>
		<!-- 底部的边框线 -->
		<image src="/static/cart_border@2x.png" class="address-border"></image>

	</view>
</template>

<script>
	//引入 vuex
	import {
		mapState,
		mapMutations,
		mapGetters
	} from 'vuex'
	export default {
		name: "my-address",
		data() {
			return {
				//申明一个空的对象的地址
				// address: {},
			};
		},
		methods: {
			...mapMutations('m_user',['udpAddress']),
			chooseAddress() {
				//获取收货地址
				uni.chooseAddress({
					success: (rs) => {						
						this.udpAddress(rs)
					}
				})
			}
		},
		computed: {
			...mapState('m_user',['address']),
			...mapGetters('m_user',['addrStr'])
		}

	}
</script>

<style lang="scss">

	.address-choose-box {
		height: 90px;
		display: flex;
		justify-content: center;
		align-items: center;

		.btnChooseAddress {}
	}

	.address-border {
		height: 5px;
		display: block;
		width: 100%;
	}

	.address-info-box {
		font-size: 12px;
		height: 90px;
		display: flex;
		padding: 0 5px;
		flex-direction: column;
		justify-content: center;

		.row1 {
			display: flex;
			justify-content: space-between;

			.row1-right {
				display: flex;
				justify-content: space-between;

				.phone {
					margin-right: 5px;
				}
			}
		}

		.row2 {
			display: flex;
			align-items: center;
			margin-top: 10px;

			/* 左边不换行，就不会被右边挤压 */
			.row2-left {
				white-space: nowrap;
			}
		}
	}
</style>
